﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.IO;

using FXnaInfrastructure;




namespace GWModflow.FileLayers.MT3DMS
{


    /// <summary>
    /// 设计用于文件输出
    /// </summary>
    public class MT3DMSFiles
    {

        public MT3DMSFiles()
        {

            _packages = new List<Package>();
 
        }

        BasicTransportPack _basicPack;

        public BasicTransportPack BasicPack
        {
            get { return _basicPack; }
            set { _basicPack = value; }
        }



        GCGSolverPack _gcgPack;

        public GCGSolverPack GcgPack
        {
            get { return _gcgPack; }
            set { _gcgPack = value; }
        }



        List<Package> _packages;

        public List<Package> Packages
        {
            get { return _packages; }
           
        }


        /// <summary>
        /// 写mt3dms*.nam文件
        /// </summary>
        protected void WriteNameFile(string FileName)
        {
            string Path =FileName+ "mt3dms.nam";
            string str = "LIST  0 mt3dms.m3d" + "\r\n";
            str += "BTN   0 mt3dms.btn" + "\r\n";
            str += "GCG   0 mt3dms.gcg" + "\r\n";  


            foreach (Package p in this._packages)
            {
                str += p.FileTypeString + "   " + p.Nunit + " " + p.Fname+"\r\n";  
            }
            str += "FTL   0 mt3dms.ftl" + "\r\n";

            FileHelper.WriteFile(Path, str);
        }

        public void WriteFiles(string path)
        {

            this.WriteNameFile(path );

            this._basicPack.WriteFile(path);


            foreach (Package p  in this._packages)
            {
                p.WriteFile(path);
                
            }



            this._gcgPack.WriteFile(path);
 
        }

        static public void DeleteMT3DFiles(string path, int speciesNumber)
        {

            try
            {

                // mt3dms.nam
                if (File.Exists (path +"mt3dms.nam"))
                {
                    File.Delete(path +"mt3dms.nam");
                }
                //mt3dms.btn

                if (File.Exists(path + "mt3dms.btn"))
                {
                    File.Delete(path + "mt3dms.btn");
                }

                //mt3dms.gcg

                if (File.Exists(path + "mt3dms.gcg"))
                {
                    File.Delete(path + "mt3dms.gcg");
                }


                //mt3dms.m3d
                if (File.Exists(path + "mt3dms.m3d"))
                {
                    File.Delete(path + "mt3dms.m3d");
                }

                //mt3dms.ssm
                if (File.Exists(path + "mt3dms.ssm"))
                {
                    File.Delete(path + "mt3dms.ssm");
                }
                //mt3dms.dsp
                if (File.Exists(path + "mt3dms.dsp"))
                {
                    File.Delete(path + "mt3dms.dsp");
                }
                //mt3dms.adv
                if (File.Exists(path + "mt3dms.adv"))
                {
                    File.Delete(path + "mt3dms.adv");
                }
                //MT3D.CNF
                if (File.Exists(path + "MT3D.CNF"))
                {
                    File.Delete(path + "MT3D.CNF");
                }
                //"mt3dms.rct"
                if (File.Exists (path +"mt3dms.rct"))
                {
                    File.Delete(path +"mt3dms.rct");
                }
                //MT3D001.UCN
                string outputFilePath = "";
                for (int i = 0; i < speciesNumber ; i++)
                {
                     outputFilePath = path + FileNameConfigHelper.GetInputFileName(i);

                    if (File.Exists(outputFilePath))
                    {
                        File.Delete(outputFilePath);
                    }

                }
                

            }
            catch
            {
                return;
            }






            

        
        }

    }
}
